#include <ptgui/ptgui.h>
#include <ptgui/pagectl.h>
#include <ptgui/pages/page.h>
#include <SDL/SDL.h>

rt_uint32_t x;
/*	Event Process Table	*/
static	void	ptgui_page_entry_handler( ptgui_page_entry_type_t Requese )
{	
	if( PTGUI_PAGE_PREPARE_FST == Requese ){
		//Do Nothing
	}
	else if ( PTGUI_PAGE_PREPARE_ALL == Requese ){
		x = 0;
	}
	else if ( PTGUI_PAGE_TERMINATE_ALL == Requese ){
		//Do Nothing
	}
	else if ( PTGUI_PAGE_TERMINATE_LST == Requese ){
	}
	else{
		//Do Nothing
	}	
}

static	ptgui_page_control_t nvdProcPsvUpdateEndCancel(pt_message_t* EventCode)
{
	return	PTGUI_PAGE_TRAN_CHANGE_REQUEST(FP_PAGE_BOOT);
}

static	ptgui_page_sw_state_t	nusGetViewPsvUpdateEndCancel(ptgui_page_switch_view_t *Switch)
{
	return	PAGE_SW_STAT_VISIBLE;
}

extern void DrawPict2(SDL_Surface *screen, char *bmpfile,
					int speedy, int flip, int nofade, int i);
extern SDL_Surface *screen;
extern int speedy, flip, nofade;
static ptgui_page_control_t (ptgui_page_render_handler)(pt_message_t* message)
{
	DrawPict2(screen, "sample.bmp", speedy, flip, nofade, x);

	return PTGUI_PAGE_TRAN_KEEP_FLAT;
}

static ptgui_page_control_t (ptgui_page_frame_handler)(pt_message_t* message)
{
	x += message->wparam / 10;
	if (x > 200)
	{
		x = 0;
	}
	return PTGUI_PAGE_TRAN_KEEP_FLAT;
}

static ptgui_page_control_t ptgui_page_mouse_handler(pt_message_t* message)
{
	ptgui_page_key_event_break();
	return PTGUI_PAGE_TRAN_RETURN_REQUEST(FP_PAGE_SIMPLE);
}
/*	Opening Cancel Key Definition	*/
PTGUI_PAGE_DEF_SW_VIEW( TswPsvUpdateEndCancel	,nvdProcPsvUpdateEndCancel ,nusGetViewPsvUpdateEndCancel	,0	,0	,0	,(KEY_ON_DO) );

/*	Static Key Table	*/
PTGUI_PAGE_BEGIN_REF_SW_VIEW_TABLE
	PTGUI_PAGE_REF_SW_VIEW( TswPsvUpdateEndCancel ),
PTGUI_PAGE_END_REF_SW_VIEW_TABLE(FP_PAGE_SIMPLE);

PTGUI_PAGE_BEGIN_DEF_EVENT_ACCEPT	
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_RENDER, ptgui_page_render_handler),
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_FRAME, ptgui_page_frame_handler),
PTGUI_PAGE_DEF_EVENT_ACCEPT(PTGUI_EVENT_MOUSE_BUTTON, ptgui_page_mouse_handler),
PTGUI_PAGE_END_DEF_EVENT_ACCEPT;

PTGUI_PAGE_DEF_PAGECELL(FP_PAGE_SIMPLE);